package filter.design;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yangluhua on 2016/8/30 0030.
 */
public abstract class FilterChain {
    public List<Filter> filters = new ArrayList();

    public String invoke(String str) {
        StringBuilder sb = new StringBuilder();
        for (Filter filter : filters) {
            sb = (StringBuilder)filter.doFilter(str);
        }
        return sb.toString();
    }

    public FilterChain add(Filter filter){
        filters.add(filter);
        return this;
    }

    public void remove(Filter filter){
        filters.remove(filter);
    }
}
